package org.meteorshower.cms_common.result;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.io.Serializable;

@Data
@NoArgsConstructor
@ToString
public class ResponseObj<T> implements AbsResponseStatus, Serializable {
    private static final long serialVersionUID = 1L;
    private Integer code;
    private String msg;
    private T data;


    public ResponseObj(Integer code, String msg, T data){
        this.code = code;
        this.msg = msg;
        this.data = data;
    }


    public static <T> ResponseObj<T> ok(T data){
        return new ResponseObj<T>(SUCCESS_CODE, SUCCESS, data);
    }
    public static ResponseObj<Void> ok(){
        return new ResponseObj<>(SUCCESS_CODE, SUCCESS, null);
    }
    public static ResponseObj<Void> error(String msg){
        return new ResponseObj<>(ERROR_CODE, msg, null);
    }
    public static ResponseObj<Void> error(){
        return new ResponseObj<>(ERROR_CODE, ERROR, null);
    }
    public static ResponseObj<Void> fail(){
        return new ResponseObj<>(FAIL_CODE, FAIL, null);
    }
    public static ResponseObj<Void> fail(String msg){
        return new ResponseObj<>(FAIL_CODE, msg, null);
    }
}
